using System;
using System.Collections.Generic;
using System.Text;

namespace Graphs
{
	class GraphUtil
	{
		public static void SearchPath(CGraph g, CNode start, CNode end)
		{
			start.HiLite = true;
			end.HiLite = true;
			return;

			Stack<CNode> stack = new Stack<CNode>();
			stack.Push(start);

			_search(g, start, stack, end);


			/*while (stack.Count > 0)
			{
				Console.WriteLine(stack.Pop().Location);
			}  */











			return;
			//doSearch(g,start);




			List<CEdge> ed = g.GetEdges(start, CNodeRole.Start);
			foreach (CEdge edge in ed)
			{
				//edge.EndNode
			}




		}

		private static void _search(CGraph g, CNode start, Stack<CNode> stack, CNode target)
		{
			List<CEdge> eds = g.GetEdges(start, CNodeRole.Start);
			stack.Push(start);


			foreach (CEdge e in eds)
			{
				if (e.EndNode == stack.Peek())
				{
					continue;
				}
				if (e.EndNode == target)
				{
					Console.WriteLine("FOUND");


					return;
				}

				_search(g, e.EndNode, stack, target);

			}













			return;







			int nOpts = eds.Count - 1;//remove one option we just walked down it to here
			if (nOpts == 0)
			{
				//dead end	 - pop, reverse
				stack.Pop();
				start.HiLite = false;
				start.Mark = true;
				if (null != g.GetEdge(stack.Peek(), start)) g.GetEdge(stack.Peek(), start).HiLite = false;
				//Console.WriteLine("POP");
			}
			else
			{
				foreach (CEdge e in eds)
				{

					if (e.EndNode == stack.Peek())
					{
						nOpts--;
						continue;
					}
					if (!e.EndNode.Mark)
					{
						if (e.EndNode == target)
						{


							CNode [] nn = stack.ToArray();
							Console.WriteLine("BOOBM");
							foreach (CNode nnn in nn)
							{
								Console.WriteLine("----------- {0}", nnn.Location);
							}

							return;
						}
						_search(g, e.EndNode, stack, target);
						e.EndNode.HiLite = true;
						e.HiLite = true;
					}
					else
					{
						e.EndNode.HiLite = !true;
						e.HiLite = !true;

					}

				}
			}



		}



	}
}
